<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>ssm整合</title>
    <!--引入vue-->
    <script th:src="@{/static/js/vue3.4.21.js}"></script>
    <!--引入axios-->
    <script th:src="@{/static/js/axios.min.js}"></script>
</head>
<body>
<div id="app">
    <button @click="getMessage">查看id=1的用户信息</button>
    <h1>{{message}}</h1>
</div><br>
<script th:inline="javascript">
    Vue.createApp({
        data(){
            return {
                message : ''
            }
        },
        methods : {
            async getMessage(){
                let response = await axios.get([[@{/}]] + 'users/1')
                this.message = response.data
            }
            }
        }).mount("#app")
</script>

<div>
    <form id="myForm">
        学生编号：<input type="text" name="sid"><br>
        学生姓名：<input type="text" name="sname"><br>
        班级编号：<input type="text" name="cid"><br>
        <button type="submit">新增用户信息</button>
    </form>
    <h1 id="newInfo"></h1>
</div>
<script>
    // 获取button按钮
    const btn = document.getElementById('myForm');
        btn.addEventListener('submit',function (event){
        event.preventDefault();
        const formData = new FormData(this);
        // 获取结果按钮
        const newInfo = document.getElementById('newInfo');
        fetch('http://localhost:8080/ssm/users/',{
            method:'POST',
            body:formData,
            headers:{
                'Content-Type':'application/json'
            }
        }).then(data=>Response.json())
            .then(data =>{
                newInfo.textContent = JSON.stringify(data);
            })
    })
</script>
</body>
</html>